package vistasSucursal;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import controlador.ControladorAC;
import controlador.ControladorSuc;
import dto.MesaDTO;
import dto.MesaSimpleDTO;
import dto.ProductoDTO;
import dto.SectorDTO;
import dto.SucursalDTO;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AperturaMesa extends javax.swing.JFrame {
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JButton unirMesas;
	private JButton abrirMesa;
	private JComboBox mesasDisponibles;
	private JButton buscarMesas;
	private JTextField comensales;

	/**
	* Auto-generated main method to display this JFrame
	*/
	
	public AperturaMesa() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Abrir Mesa");
				jLabel1.setBounds(25, 18, 76, 16);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Cantidad de Comensales");
				jLabel2.setBounds(25, 64, 155, 16);
			}
			{
				comensales = new JTextField();
				getContentPane().add(comensales);
				comensales.setBounds(183, 61, 54, 23);
			}
			{
				buscarMesas = new JButton();
				getContentPane().add(buscarMesas);
				buscarMesas.setText("Buscar Mesas Disponibles");
				buscarMesas.setBounds(263, 61, 216, 23);
				buscarMesas.addActionListener(new ActionListener() {
					@SuppressWarnings({ "null", "unchecked" })
					public void actionPerformed(ActionEvent evt) {
						SectorDTO sec=new SectorDTO();
						int id=1;
						sec.setIdSector(id);
						
						List<MesaDTO> mesas = ControladorSuc.getInstancia().listarMesasPorSector(sec, Integer.parseInt(comensales.getText()));
						
						if (mesas != null) {
							for (MesaDTO m:mesas){
	//							Object[] object = new Object[3];
	//							object[1]=m.getNumero();
	//							object[2]=" ";
	//							object[3]=m.getIdMesa();
								mesasDisponibles.addItem(m);
							}
						}
						
//						JOptionPane.showMessageDialog(null, "Se dio de alta una tarea para la sucursal " + suc.getNombre());
//						dispose();
					}
				});
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Mesas Disponibles");
				jLabel3.setBounds(25, 126, 138, 16);
			}
			{
//				ComboBoxModel mesasDisponiblesModel = 
//						new DefaultComboBoxModel(
//								new String[] { "Item One", "Item Two" });
				mesasDisponibles = new JComboBox();
				getContentPane().add(mesasDisponibles);
//				mesasDisponibles.setModel(mesasDisponiblesModel);
				mesasDisponibles.setBounds(182, 122, 133, 23);
			}
			{
				abrirMesa = new JButton();
				getContentPane().add(abrirMesa);
				abrirMesa.setText("Abrir Mesa");
				abrirMesa.setBounds(25, 286, 71, 23);
				abrirMesa.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
					//	MesaSimpleDTO m=new MesaSimpleDTO();
					//	m.setNumero((int)mesasDisponibles.getSelectedItem());
						MesaSimpleDTO m=(MesaSimpleDTO)mesasDisponibles.getSelectedItem();
						ControladorSuc.getInstancia().abrirMesa(m, null);
						}
				}
				);
				
			}
			{
				unirMesas = new JButton();
				getContentPane().add(unirMesas);
				unirMesas.setText("Ir a Unir Mesas");
				unirMesas.setBounds(123, 286, 91, 23);
			}
			pack();
			this.setSize(514, 385);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
